<template>
  <div class="body1" style="padding-top:10px;">
      <div class="form_select">
        <div>
          <el-input class="select_input" size="small" 
          v-model="form.username" placeholder="员工姓名"></el-input>
          <el-button type="primary"  size="small" @click="getList">搜索</el-button>
        </div>
        <div class="select_right">
          <el-button type="primary"  size="small" @click="addClick()">添加员工</el-button>
        </div>
      </div>
      <staffTable :list="list" @func="editTrue"></staffTable>
      <staffEdit :id="id" :show="editShow" :roleArr="roleArr" :role="role" @func="editTrue"></staffEdit>
      <staffAdd :show="addShow" :roleArr="roleArr" @func="editTrue"></staffAdd>
  </div>
</template>
 
<script>
import staffTable from "./staffTable"
import staffEdit from "./staffEdit"
import staffAdd from "./staffAdd"
export default {
  name: "Staff",
  data() {
    return {
      form:{},
      list:[],
      id:0,
      editShow:false,
      addShow:false,
      roleArr:[],
      role:0
    };
  },
   components: {
    "staffTable": staffTable,
    "staffEdit":staffEdit,
    "staffAdd":staffAdd
  },
  created: function() {
    //console.log(process.env.NODE_ENV);
    this.getList();
  },
  methods: {
    getList:function(){
        this.form.store_id = localStorage.getItem('store_id')
        var that = this
        this.$get('staff/all',this.form).then((res) => {
            that.list = res.data
        })
    },
    editTrue:function(data){
      this.id = data.id
      this.role = data.role
      this[data.key] = !this[data.key]
      if(data.type){
        this.getList()
      }
      if(data.id){
        if(this.roleArr.length == 0){
          var that = this
          this.$get('role/all',{}).then((res) => {
              that.roleArr = res.data
          })
        }
      }
    },
    addClick:function(){
      if(this.roleArr.length == 0){
        var that = this
        this.$get('role/all',{}).then((res) => {
            that.roleArr = res.data
        })
      }
      this.addShow = true
    }
  }
};
</script>
<style>
</style>